class Solution {
public:
    int peopleAwareOfSecret(int n, int delay, int forget) {
        vector<int> arr(n);
        arr[0] = 1;
        int mod = 1e9 + 7;
        for (int i = 0; i < n; i++) {
            if (arr[i] == 0) continue;
            int left = i + delay, right = i + forget - 1;
            for (int j = left; j <= min(n - 1, right); j++)
                arr[j] = (arr[j] + arr[i]) % mod;
        }
        int ret = 0;
        for (int i = n - forget; i < n; i++)
            ret = (ret + arr[i]) % mod;
        return ret;
    }
};

class Solution {
public:
    int peopleAwareOfSecret(int n, int delay, int forget) {
        vector<int> arr(n);
        arr[0] = 1;
        int mod = 1e9 + 7, newn = 0;
        for (int i = delay; i < n; i++) {
            if (i < forget) newn = (newn + arr[i - delay]) % mod;
            else {
                newn = (newn + arr[i - delay]) % mod;
                newn = (newn + mod - arr[i - forget]) % mod;
            }
            arr[i] = newn;
        }

        int ret = 0;
        for (int i = n - forget; i < n; i++)
            ret = (ret + arr[i]) % mod;
        return ret;
    }
};